home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / showEditor.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  68.5 KB  |  2,346 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //    Alias|Wavefront Script File
  19. //
  20. //    Creation Date:        March 8, 1996
  21. //    Original Author:    js
  22. //
  23. //    Major Revisions:     July 23, 1997
  24. //    Author:                ajp
  25. //
  26. //    Major Revisions:     November 25, 1998
  27. //    Author:                jb
  28. //
  29. //    Procedure Name:
  30. //    showEditor
  31. //
  32. //    Description Name;
  33. //    builds all the base UI for the attribute editor
  34. //
  35. //    Input Value:
  36. //    nodeName
  37. //
  38. //    Output Value:
  39. //    None
  40. //
  41.  
  42. global string    $gAttributeEditorWindowName = "AEWindow";
  43. global string    $gAENothingSelectedLayout = "AENothingSelectedLayout";
  44. global string     $gAEMenuBarLayoutName = "AEmenuBarLayout";
  45. global string   $gAERootLayoutName = "AErootLayout";
  46. global string    $gAERootPaneLayoutName = "AErootLayoutPane";
  47. global string   $gAEHeaderLayoutName = "AEheaderLayout";
  48. global string   $gAETabLayoutName = "AEtabLayout";
  49. global string   $gAEBaseLayoutName = "AEbaseFormLayout";
  50. global string   $gAEControlLayoutName = "AEcontrolFormLayout";
  51. global string   $gAENodeStack[];
  52. global string    $gLastViewedAEType = "";
  53. global int        $gAutoUpdateAttrEdFlag;
  54. global string    $gRelatedNodes[];    // used to store full names for DAG objects
  55. global string    $gAECurrentTab = "";
  56. global string    $gAEPrevCurrentTab = "";
  57. global string    $gAETabMarker[];
  58. global int        $gAESelectionScriptJob = 0;
  59. global int        $gAEConstructionScriptJob = 0;
  60.  
  61. //    This global fixes a problem with double updates. The showEditor() 
  62. //    procedure may change the visibility of the AE in the main window.
  63. //    That will result in additional update of the AE. We need this flag
  64. //    to ignore the second update in attributeEditorVisibilityStateChange().
  65. //
  66. //    See bug #138766 and #145364.
  67. //
  68. global int        $gIgnoreAEUpdate = false;
  69.  
  70. //    NOTE: shadingEngine nodes do not have documentation right now, so don't
  71. //    show them in the Attribute Editor > Help menu. When it does get 
  72. //    documentation, this statement can be removed.
  73. //
  74. //    By reading the documentation for addAttributeEditorNodeHelp() you
  75. //    will see that specifying an empty string second argument prevents
  76. //    a help menu item from being created for the specified node type.
  77. //
  78. addAttributeEditorNodeHelp("shadingEngine", "");
  79.  
  80. global proc resetAEGlobalVariables()
  81. {
  82.     global string    $gAErenderGlobalsQualityLUT[];
  83.     global string    $gAErenderGlobalsResolutionLUT[];
  84.     global string   $gAENodeStack[];
  85.     global string   $gRelatedNodes[];
  86.     global string   $gLastViewedAEType;
  87.     global string   $gAETabMarker[];
  88.     global string    $gAEIKHandleMenus[];
  89.     global string    $gTransformLimitsUILUT[];
  90.     global string    $gAEmotionPathWorldUpWidgets[];
  91.     global string    $gAEmotionPathFollowCBG[];
  92.     global string    $gAEaimConstraintWorldUpWidgets[];
  93.     global string    $gAEnormalConstraintWorldUpWidgets[];
  94.     global string    $gAEtangentConstraintWorldUpWidgets[];
  95.  
  96.     clear $gAErenderGlobalsQualityLUT;
  97.     clear $gAErenderGlobalsResolutionLUT;
  98.     clear $gAENodeStack;
  99.     clear $gRelatedNodes;
  100.     clear $gAETabMarker;
  101.     clear $gAEIKHandleMenus;
  102.     clear $gTransformLimitsUILUT;
  103.     clear $gAEmotionPathWorldUpWidgets;
  104.     clear $gAEmotionPathFollowCBG;
  105.     clear $gAEaimConstraintWorldUpWidgets;
  106.     clear $gAEnormalConstraintWorldUpWidgets;
  107.     clear $gAEtangentConstraintWorldUpWidgets;
  108.  
  109.     $gLastViewedAEType = "";
  110. }
  111.  
  112. proc int haveAttributeEditorHelpCommand(string $nodeType)
  113. //
  114. //    Description:
  115. //        Determine if a help command is specified for the argument
  116. //        node type.
  117. //
  118. //    Returns:
  119. //        True if a help command is associated with the node type.
  120. //
  121. //    Notes:
  122. //        See addAttributeEditorNodeHelp.mel for adding nodes and
  123. //        help commands.
  124. //
  125. {
  126.     global string $gAttributeEditorNodeTypeArray[];
  127.  
  128.     int $result = false, $index, $length;
  129.  
  130.     $length = size($gAttributeEditorNodeTypeArray);
  131.  
  132.     //    Search the array for the node type.
  133.     //
  134.     for ($index = 0; $index < $length; $index++) {
  135.         if ($nodeType == $gAttributeEditorNodeTypeArray[$index]) {
  136.             $result = true;
  137.             break;
  138.         }
  139.     }
  140.  
  141.     return $result;
  142. }
  143.  
  144. proc string getAttributeEditorHelpCommand(string $nodeType)
  145. //
  146. //    Description:
  147. //        Return the help command for the argument node type.
  148. //
  149. //    Returns:
  150. //        The help command or an empty string.
  151. //
  152. //    Notes:
  153. //        See addAttributeEditorNodeHelp.mel for adding nodes and
  154. //        help commands.
  155. //
  156. {
  157.     global string $gAttributeEditorNodeTypeArray[];
  158.     global string $gAttributeEditorHelpCommandArray[];
  159.  
  160.     string $helpCommand = "";
  161.  
  162.     int $index, $length;
  163.  
  164.     $length = size($gAttributeEditorNodeTypeArray);
  165.  
  166.     //    Search the array for the node type. If found then get the
  167.     //    associated help command.
  168.     //
  169.     for ($index = 0; $index < $length; $index++) {
  170.         if ($nodeType == $gAttributeEditorNodeTypeArray[$index]) {
  171.             $helpCommand = $gAttributeEditorHelpCommandArray[$index];
  172.             break;
  173.         }
  174.     }
  175.  
  176.     return $helpCommand;
  177. }
  178.  
  179. proc string AEnoSlash ( string $a )
  180. {
  181.     string  $buf[];
  182.     int     $size = `tokenize $a "|/-" $buf`;
  183.     string  $retval = "";
  184.  
  185.     $retval = $buf[$size - 1];
  186.     return $retval;
  187. }
  188.  
  189.  
  190. proc string[] showEditorGetList()
  191. //
  192. // This private method returns the correct list of
  193. // objects, based on the value of the optionVar named
  194. // "attrEdListType".  If this variable does not yet
  195. // exist, it is created and set to "selected"
  196. //
  197. {
  198.     // Get the current list type from the option variables.
  199.     //
  200.     string $listType = "selected";
  201.     if ( `optionVar -exists "attrEdListType"` ){
  202.         $listType = `optionVar -q "attrEdListType"`;
  203.     }
  204.  
  205.     string $outList[];
  206.  
  207.     string $textures2D[] = { "bulge",
  208.                              "checker",
  209.                              "cloth",
  210.                              "file",
  211.                              "fractal",
  212.                              "grid",
  213.                              "mountain",
  214.                              "ramp",
  215.                              "water",
  216.                              "noise",
  217.                              "ocean",
  218.                              "fluidTexture2D" };
  219.     string $textures3D[] = { "brownian",
  220.                              "cloud",
  221.                              "crater",
  222.                              "granite",
  223.                              "leather",
  224.                              "marble",
  225.                              "rock",
  226.                              "snow",
  227.                              "solidFractal",
  228.                              "stucco",
  229.                              "wood",
  230.                              "volumeNoise",
  231.                              "fluidTexture3D" };
  232.     string $texturesEnv[] = {"envBall",
  233.                              "envChrome",
  234.                              "envCube",
  235.                              "envSky",
  236.                              "envSphere" };
  237.     string $texturesOther[] = {"layeredTexture" };
  238.  
  239.     // Depending on the list type, get the right list
  240.     // of objects.
  241.     //
  242.     switch( $listType ){
  243.       case "selected":
  244.       case "auto":
  245.         $outList = `ls -sl`;
  246.         break;
  247.       case "particle":
  248.         $outList = `ls -type particle`;
  249.         break;
  250.       case "emitter":
  251.         $outList = `ls -type pointEmitter`;
  252.         break;
  253.       case "spring":
  254.         $outList = `ls -type spring`;
  255.         break;
  256.       case "air":
  257.         $outList = `ls -type airField`;
  258.         break;
  259.       case "drag":
  260.         $outList = `ls -type dragField`;
  261.         break;
  262.       case "gravity":
  263.         $outList = `ls -type gravityField`;
  264.         break;
  265.       case "newton":
  266.         $outList = `ls -type newtonField`;
  267.         break;
  268.       case "radial":
  269.         $outList = `ls -type radialField`;
  270.         break;
  271.       case "turbulence":
  272.         $outList = `ls -type turbulenceField`;
  273.         break;
  274.       case "uniform":
  275.         $outList = `ls -type uniformField`;
  276.         break;
  277.       case "vortex":
  278.         $outList = `ls -type vortexField`;
  279.         break;
  280.       case "rigidSolver":
  281.         $outList = `ls -type rigidSolver`;
  282.         break;
  283.       case "rigidBody":
  284.         $outList = `ls -type rigidBody`;
  285.         break;
  286.       case "rigidConstraint":
  287.         $outList = `ls -type rigidConstraint`;
  288.         break;
  289.       case "rigidSolver":
  290.         $outList = `ls -type rigidSolver`;
  291.         break;
  292.       case "rigidBody":
  293.         $outList = `ls -type rigidBody`;
  294.         break;
  295.       case "rigidConstraint":
  296.         $outList = `ls -type rigidConstraint`;
  297.         break;
  298.       case "fluidShape":
  299.         $outList = `ls -type fluidShape`;
  300.         break;
  301.       case "joint":
  302.         $outList = `ls -type joint`;
  303.         break;
  304.       case "handle":
  305.         $outList = `ls -type ikHandle`;
  306.         break;
  307.       case "ikSystem":
  308.         $outList = `ls -type ikSystem`;
  309.         break;
  310.       case "ikSolver":
  311.         $outList = `ikSystem -q -ls`;
  312.         break;
  313.       case "blendShape":
  314.         $outList = `ls -type blendShape`;
  315.         break;
  316.       case "cluster":
  317.         $outList = `ls -type cluster`;
  318.         break;
  319.       case "flexor":
  320.         $outList = `ls -type flexorShape`;
  321.         break;
  322.       case "lattice":
  323.         $outList = `ls -type lattice`;
  324.         break;
  325.       case "sculpt":
  326.         $outList = `ls -type sculpt`;
  327.         break;
  328.       case "wire":
  329.         $outList = `ls -type wire`;
  330.         break;
  331.       case "allLights":
  332.         $outList = `ls -type spotLight -type directionalLight
  333.             -type ambientLight -type pointLight`;
  334.         break;
  335.       case "spotLight":
  336.         $outList = `ls -type spotLight`;
  337.         break;
  338.       case "pointLight":
  339.         $outList = `ls -type pointLight`;
  340.         break;
  341.       case "directionalLight":
  342.         $outList = `ls -type directionalLight`;
  343.         break;
  344.       case "ambientLight":
  345.         $outList = `ls -type ambientLight`;
  346.         break;
  347.       case "volumeLight":
  348.         $outList = `ls -type volumeLight`;
  349.         break;
  350.       case "shadingGrp":
  351.         $outList = `ls -type shadingEngine`;
  352.         break;
  353.       case "allTextures":
  354.         string $cmd = "ls ";
  355.         for( $texture in $textures2D ) {
  356.             $cmd = ( $cmd + " -type " + $texture + " " );
  357.         }
  358.         for( $texture in $textures3D ) {
  359.             $cmd = ( $cmd + " -type " + $texture + " " );
  360.         }
  361.         for( $texture in $texturesEnv ) {
  362.             $cmd = ( $cmd + " -type " + $texture + " " );
  363.         }
  364.         for( $texture in $texturesOther ) {
  365.             $cmd = ( $cmd + " -type " + $texture + " " );
  366.         }
  367.         $outList = `eval $cmd`;
  368.         break;
  369.       case "textures2D":
  370.         string $cmd = "ls ";
  371.         for( $texture in $textures2D ) {
  372.             $cmd = ( $cmd + " -type " + $texture + " " );
  373.         }
  374.         $outList = `eval $cmd`;
  375.         break;
  376.       case "textures3D":
  377.         string $cmd = "ls ";
  378.         for( $texture in $textures3D ) {
  379.             $cmd = ( $cmd + " -type " + $texture + " " );
  380.         }
  381.         $outList = `eval $cmd`;
  382.         break;
  383.       case "texturesEnv":
  384.         string $cmd = "ls ";
  385.         for( $texture in $texturesEnv ) {
  386.             $cmd = ( $cmd + " -type " + $texture + " " );
  387.         }
  388.         $outList = `eval $cmd`;
  389.         break;
  390.     }
  391.  
  392.     return $outList;
  393. }
  394.  
  395. global proc showEditorHelpMenu()
  396. //
  397. //  Description:
  398. //        Called right before the help menu is shown.
  399. //        A "Help on <node type>..." menu item is built for each 
  400. //        type of    node currently shown in the Attribute Editor.
  401. //        
  402. //  Return Value:
  403. //      None
  404. {
  405.     global string    $gRelatedNodes[];
  406.     global string    $gAEBaseLayoutName;
  407.  
  408.     // Clear out the current help menu.
  409.     //
  410.     setParent -menu AEhelpMenu;
  411.     menu -edit -deleteAllItems AEhelpMenu;
  412.  
  413.  
  414.     // Create first item that opens help for the window.
  415.     //
  416.     menuItem -label "Help on Attribute Editor..."
  417.         -enableCommandRepeat false
  418.         -command "showHelp AttributeEditor";
  419.  
  420.     menuItem -divider true;
  421.  
  422.     // If there are tabs showing (i.e. something's showing
  423.     // in the Attribute Editor) then build help items for
  424.     // each node type shown.
  425.     //
  426.     if (`formLayout -query -visible $gAEBaseLayoutName`) {
  427.  
  428.         string $nodeTypes[];
  429.         int    $numNodes = size($gRelatedNodes);
  430.         int $numTypes = 0;
  431.         int $i;
  432.         int $j;
  433.  
  434.         // For each node in the AE, get it's type and if it's not a duplicate
  435.         // then add it to the $nodeTypes[] array.
  436.         //
  437.         for ($i = 0; $i < $numNodes; $i++) {
  438.  
  439.             string $type = `nodeType $gRelatedNodes[$i]`;
  440.             int $found = false;
  441.  
  442.             for ($j = 0; $j < $numTypes; $j++) {
  443.                 if ($type == $nodeTypes[$j]) {
  444.                     $found = true;
  445.                     break;
  446.                 }
  447.             }
  448.  
  449.             if (!$found) {
  450.                 $nodeTypes[$numTypes] = $type;
  451.                 $numTypes++;
  452.             }
  453.         }
  454.  
  455.         $nodeTypes = `sort $nodeTypes`;
  456.  
  457.         // Create a menu item for each type that was found.
  458.         //
  459.         for ($i = 0; $i < $numTypes; $i++) {
  460.  
  461.             string $type = $nodeTypes[$i];
  462.  
  463.             //    Check if a help command has been specified 
  464.             //    by the user.
  465.             //
  466.             if (haveAttributeEditorHelpCommand($type)) {
  467.                 string $helpCommand = getAttributeEditorHelpCommand($type);
  468.                 //
  469.                 //    Help command may be set to empty string if user does
  470.                 //    not want menu item entry for node type.
  471.                 //
  472.                 if ("" != $helpCommand) {
  473.                     menuItem -label ("Help on \"" + $type + "\"...")
  474.                         -enableCommandRepeat false
  475.                         -command ($helpCommand);
  476.                 }
  477.  
  478.             } else {
  479.                 //    Provide a menu item pointing to our default location
  480.                 //    for node documentation.
  481.                 //
  482.                 string $cmd = "showHelp -docs \"Nodes/" + $type + ".html\"";
  483.                 menuItem -label ("Help on \"" + $type + "\"...")
  484.                     -enableCommandRepeat false
  485.                     -command ($cmd);
  486.             }
  487.         }
  488.  
  489.         menuItem -divider true;
  490.     }
  491.  
  492.     // Create last item that opens help for all nodes.
  493.     //
  494.     menuItem -label "Node and Attribute Reference..."
  495.         -enableCommandRepeat false
  496.         -command "showHelp -docs \"Nodes/index.html\"";
  497. }
  498.  
  499. global proc showEditorCreateMenu()
  500. //
  501. // This is called just before the object menu on the
  502. // attribute editor is posted.  It looks to see what
  503. // kind of objects need to be listed, then updates
  504. // the menu to contain the appropriate list.
  505. //
  506. {
  507.     string $nameList[] = showEditorGetList();
  508.  
  509.     int $limit = size($nameList);
  510.     if ( $limit > 30 ){
  511.         $limit = 30;
  512.     }
  513.     int $i;
  514.  
  515.     string $listType = "Nothing selected";
  516.     if ( `optionVar -exists "attrEdListType"` ){
  517.         $listType = `optionVar -q "attrEdListType"`;
  518.     }
  519.  
  520.     setParent -menu objectMenu;
  521.     menu -e -dai objectMenu;
  522.  
  523.     if( $limit == 0 ) {
  524.         if( $listType == "auto" || $listType == "selected" ) {
  525.             menuItem -l "There is nothing selected"
  526.         -enable false;
  527.         } else {
  528.             menuItem -l ( "No " + $listType + " objects in the system" );
  529.         }
  530.     } else {
  531.         for ( $i=0; $i<$limit; $i++ ){
  532.             menuItem
  533.                 -c ("commitAENotes($gAECurrentTab);showEditor \"" + $nameList[$i] + "\";")
  534.                 -l $nameList[$i];
  535.         }
  536.     }
  537. }
  538.  
  539.  
  540. global proc showEditorFocusMenu()
  541. // This proc is called just before the Focus menu on the attribute
  542. // editor is posted.  It looks to see what objects are on the
  543. // focus stack, then updates the menu to contain the apprpriate
  544. // list
  545. //
  546. {
  547.     global string    $gAENodeStack[];
  548.  
  549.     setParent -menu focusMenu;
  550.  
  551.     int $i = 0;
  552.     string $mI;
  553.  
  554.     for ($i = 0; $i < size($gAENodeStack); $i++) {
  555.         $mI = ("SEFM"+$i);
  556.         if (`menuItem -exists $mI`) {
  557.             if ( `objExists $gAENodeStack[$i]` ) {
  558.                 menuItem -e
  559.                     -l ($gAENodeStack[$i])
  560.                     -c ("commitAENotes($gAECurrentTab);showEditorExact \"" + $gAENodeStack[$i] + "\"")
  561.                     $mI;
  562.             } else {
  563.                 deleteUI $mI;
  564.             }
  565.         } else {
  566.             if ( `objExists $gAENodeStack[$i]` ) {
  567.                 menuItem
  568.                     -l ($gAENodeStack[$i])
  569.                     -c ("commitAENotes($gAECurrentTab);showEditorExact \"" + $gAENodeStack[$i] + "\"")
  570.                     $mI;
  571.             }
  572.         }
  573.     }
  574.  
  575.     // Remove any excess items
  576.     int $notDone = true;
  577.     $i = size($gAENodeStack);
  578.     while ($notDone) {
  579.         $mI = ("SEFM"+$i);
  580.         if (`menuItem -exists $mI`) {
  581.             deleteUI -menuItem $mI;
  582.             $i++;
  583.         } else {
  584.             $notDone = false;
  585.         }
  586.     }
  587. }
  588.  
  589.  
  590.  
  591. // Iterates over all the children in the formLayout and
  592. // attaches them all accordingly
  593. //
  594. proc AEattachEditor( string $formLayoutName )
  595. {
  596.     setParent $formLayoutName;
  597.     // attach the internal layouts
  598.     string $formChildren[] = `formLayout -q -ca $formLayoutName`;
  599.     if (size($formChildren) > 0) {
  600.         string $attachCmd = "formLayout -e ";
  601.         $attachCmd += (" -af " + $formChildren[0] + " top 5 ");
  602.         for ($i = 0; $i < size($formChildren); $i++) {
  603.             if ($i != 0) {
  604.                 $attachCmd += (" -ac " + $formChildren[$i] +
  605.                                 " top 5 " + $formChildren[$i-1]);
  606.             }
  607.             $attachCmd += (" -af " + $formChildren[$i] +
  608.                             " left 0 ");
  609.             $attachCmd += (" -af " + $formChildren[$i] +
  610.                             " right 0 ");
  611.         }
  612.     if (`scrollLayout -exists $formChildren[$i-1]`)
  613.             $attachCmd += (" -af " + $formChildren[$i-1] + " bottom 0 ");
  614.         $attachCmd += $formLayoutName;
  615.         eval $attachCmd;
  616.     }
  617.     setParent ..;
  618. }
  619.  
  620.  
  621. // Updates the title of tear off windows when the
  622. // node their displaying is renamed.  Also rebuild
  623. // the contained attribute editor to ensure that
  624. // all the callbacks are correct.
  625. //
  626. global proc updateTearOffTitle( string $windowName, string $edLayout )
  627. {
  628.     // get the previous UI parent
  629.     //
  630.     string $prevUIParent = `setParent -q`;
  631.  
  632.     // set the parent to this tear-off window
  633.     // so that we get the correct nameField
  634.     //
  635.     setParent $windowName;
  636.  
  637.     // get the name
  638.     //
  639.     string $name = `nameField -q -o tearOffNameField`;
  640.  
  641.     // we only want to display the last item, not the
  642.     // full path name
  643.     //
  644.     string $tokens[];
  645.     tokenize($name,"|",$tokens);
  646.     string $shortName = $tokens[size($tokens)-1];
  647.  
  648.     // update the window's title
  649.     //
  650.     window -e -title $shortName -in $shortName $windowName;
  651.     
  652.     // rebuild the attribute editor
  653.     //
  654.     createEditor $edLayout $name;
  655.  
  656.     // reset the UI parent
  657.     //
  658.     setParent $prevUIParent;
  659. }
  660.  
  661.  
  662. // This method duplicates the current attribute editor into
  663. // another window.  The new window doens't have all the fancy
  664. // features, and cannot be switched.
  665. //
  666. global proc copyAEWindow()
  667. {
  668.     global string   $gAECurrentTab;
  669.     global string    $gAttributeEditorWindowName;
  670.     global string    $gAEMenuBarLayoutName;
  671.  
  672.     if ( $gAECurrentTab != "" ) {
  673.  
  674.         int $width = `menuBarLayout -q -width $gAEMenuBarLayoutName`;
  675.         int $height = `menuBarLayout -q -height $gAEMenuBarLayoutName`;
  676.  
  677.         // create the window
  678.         string $tokens[];
  679.         tokenize($gAECurrentTab,"|",$tokens);
  680.         string $windowTitle = $tokens[size($tokens)-1];
  681.         $windowName = `window
  682.             -t $windowTitle
  683.             -in $windowTitle
  684.             -w $width -h $height`;
  685.  
  686.         setUITemplate -pushTemplate attributeEditorTemplate;
  687.  
  688.     string $topLayout = `formLayout`;
  689.  
  690.         string $layoutName = `formLayout`;
  691.  
  692.         // create a nameField so that the window's
  693.         // title gets updated correctly if the node is
  694.         // renamed
  695.         //
  696.         string $nodeType = `nodeType $gAECurrentTab`;
  697.         separator -style none -h 10;
  698.         rowLayout -nc 2;
  699.             text -l ($nodeType+":");
  700.             nameField -o $gAECurrentTab -ncc ("updateTearOffTitle " + $windowName + " " + $layoutName ) tearOffNameField;
  701.         setParent ..;
  702.         separator -style none -h 10;
  703.  
  704.         // create the editor in the window
  705.         createEditor $layoutName $gAECurrentTab;
  706.  
  707.         AEattachEditor $layoutName;
  708.  
  709.     // Create the Select and Close buttons at the bottom of the
  710.     // tear-off window.
  711.     //
  712.     setParent $topLayout;
  713.     string $selectButton = `button -label "Select"
  714.         -command ("select " + $gAECurrentTab)`;
  715.     string $closeButton = `button -label "Close"
  716.         -command ("deleteUI "+$windowName)`;
  717.     formLayout -edit
  718.         -attachForm    $selectButton    "bottom"  5
  719.         -attachForm    $selectButton    "left"    5
  720.         -attachPosition    $selectButton    "right"   2 50
  721.         -attachForm    $closeButton    "bottom"  5
  722.         -attachForm    $closeButton    "right"   5
  723.         -attachPosition    $closeButton    "left"    3 50
  724.  
  725.         -attachControl    $layoutName    "bottom"  5 $selectButton
  726.         -attachForm    $layoutName    "top"     5
  727.         -attachForm    $layoutName    "left"    5
  728.         -attachForm    $layoutName    "right"   5
  729.         $topLayout;
  730.  
  731.         setUITemplate -popTemplate;
  732.  
  733.         showWindow $windowName;
  734.     }
  735. }
  736.  
  737.  
  738. // Post the Rename Attribute window. 
  739. //
  740. global proc  showRenameAttrWin()
  741. {
  742.     global string   $gAECurrentTab;
  743.     if ( $gAECurrentTab != "" )
  744.         dynRenameAttrWin( {} );    
  745. }
  746.  
  747. // Post the Delete Attribute window. 
  748. //
  749. global proc  showDeleteAttrWin()
  750. {
  751.     global string   $gAECurrentTab;
  752.     if ( $gAECurrentTab != "" )
  753.         dynDeleteAttrWin( {} );
  754. }
  755.  
  756. // Post the Add Attribute window. 
  757. //
  758. global proc  showAddAttrWin()
  759. {
  760.     global string   $gAECurrentTab;
  761.     if ( $gAECurrentTab != "" )
  762.         dynAddAttrWin( {} );
  763. }
  764.  
  765.  
  766. // Build the menus.  The optionVar attrEdListType is used to
  767. // retain the list type.
  768. //
  769. proc buildAEMenus ( string $parent )
  770. {
  771.     setParent $parent;
  772.  
  773.     string $listType = "auto";
  774.     if ( `optionVar -exists "attrEdListType"` ) {
  775.         $listType = `optionVar -q "attrEdListType"`;
  776.     }
  777.  
  778.     menu -l "List" 
  779.     -familyImage "menuIconList.xpm"
  780.     listMenu;
  781.         string $listCluster = `radioMenuItemCollection`;
  782.         menuItem -l "Auto Load Selected Attributes"
  783.             -cb ($listType == "auto")
  784.             -c "showEditorSetListType(\"auto\")"
  785.             AEautoUpdateMenuItem;
  786.         menuItem -l "Load Selected Attributes"
  787.             -c ("editSelected")
  788.             AEreloadSelectedMenuItem;
  789.         menuItem -l "Selected Items"
  790.             -rb ($listType == "selected")
  791.             -cl $listCluster
  792.             -c "showEditorSetListType(\"selected\")"
  793.             AEselectedItemsMenuItem;
  794.         menuItem -d true;
  795.         menuItem -l "Dynamics" -subMenu true AEdynamicsSubMenu;
  796.             menuItem -l "Particles"
  797.                 -rb ($listType == "particle")
  798.                 -cl $listCluster
  799.                 -c "showEditorSetListType(\"particle\")";
  800.             menuItem -l "Emitters"
  801.                 -rb ($listType == "emitter")
  802.                 -cl $listCluster
  803.                 -c "showEditorSetListType(\"emitter\")";
  804.             menuItem -l "Springs"
  805.                 -rb ($listType == "spring")
  806.                 -cl $listCluster
  807.                 -c "showEditorSetListType(\"spring\")";
  808.             menuItem -l "Gravity Fields"
  809.                 -rb ($listType == "gravity")
  810.                 -cl $listCluster
  811.                 -c "showEditorSetListType(\"gravity\")";
  812.             menuItem -l "Drag Fields"
  813.                 -rb ($listType == "drag")
  814.                 -cl $listCluster
  815.                 -c "showEditorSetListType(\"drag\")";
  816.             menuItem -l "Air Fields"
  817.                 -rb ($listType == "air")
  818.                 -cl $listCluster
  819.                 -c "showEditorSetListType(\"air\")";
  820.             menuItem -l "Newton Fields"
  821.                 -rb ($listType == "newton")
  822.                 -cl $listCluster
  823.                 -c "showEditorSetListType(\"newton\")";
  824.             menuItem -l "Radial Fields"
  825.                 -rb ($listType == "radial")
  826.                 -cl $listCluster
  827.                 -c "showEditorSetListType(\"radial\")";
  828.             menuItem -l "Turbulence Fields"
  829.                 -rb ($listType == "turbulence")
  830.                 -cl $listCluster
  831.                 -c "showEditorSetListType(\"turbulence\")";
  832.             menuItem -l "Uniform Fields"
  833.                 -rb ($listType == "uniform")
  834.                 -cl $listCluster
  835.                 -c "showEditorSetListType(\"uniform\")";
  836.             menuItem -l "Vortex Fields"
  837.                 -rb ($listType == "vortex")
  838.                 -cl $listCluster
  839.                 -c "showEditorSetListType(\"vortex\")";
  840.             menuItem -l "Rigid Solver"
  841.                 -rb ($listType == "rigidSolver")
  842.                 -cl $listCluster
  843.                 -c "showEditorSetListType(\"rigidSolver\")";
  844.             menuItem -l "Rigid Bodies"
  845.                 -rb ($listType == "rigidBody")
  846.                 -cl $listCluster
  847.                 -c "showEditorSetListType(\"rigidBody\")";
  848.             menuItem -l "Rigid Constraints"
  849.                 -rb ($listType == "rigidConstraint")
  850.                 -cl $listCluster
  851.                 -c "showEditorSetListType(\"rigidConstraint\")";
  852.             if( fluidEditLicenseFound() ) {
  853.                 menuItem -l "Fluids"
  854.                     -rb ($listType == "fluidShape")
  855.                     -cl $listCluster
  856.                     -c "showEditorSetListType(\"fluidShape\")";
  857.             }
  858.             setParent -menu ..;
  859.         menuItem -l "Kinematics" -subMenu true AEkinematicsSubMenu;
  860.             menuItem -l "Joints"
  861.                 -rb ($listType == "joint")
  862.                 -cl $listCluster
  863.                 -c "showEditorSetListType(\"joint\")";
  864.             menuItem -l "Handles"
  865.                 -rb ($listType == "handle")
  866.                 -cl $listCluster
  867.                 -c "showEditorSetListType(\"handle\")";
  868.             menuItem -l "IK Systems"
  869.                 -rb ($listType == "ikSystem")
  870.                 -cl $listCluster
  871.                 -c "showEditorSetListType(\"ikSystem\")";
  872.             menuItem -l "IK Solvers"
  873.                 -rb ($listType == "ikSolver")
  874.                 -cl $listCluster
  875.                 -c "showEditorSetListType(\"ikSolver\")";
  876.             setParent -menu ..;
  877.         menuItem -l "Deformers" -subMenu true AEdeformersSubMenu;
  878.             menuItem -l "Blend Shape"
  879.                 -rb ($listType == "blendShape")
  880.                 -cl $listCluster
  881.                 -c "showEditorSetListType(\"blendShape\")";
  882.             menuItem -l "Cluster"
  883.                 -rb ($listType == "cluster")
  884.                 -cl $listCluster
  885.                 -c "showEditorSetListType(\"cluster\")";
  886.             menuItem -l "Flexor"
  887.                 -rb ($listType == "flexorShape")
  888.                 -cl $listCluster
  889.                 -c "showEditorSetListType(\"flexor\")";
  890.             menuItem -l "Lattice"
  891.                 -rb ($listType == "lattice")
  892.                 -cl $listCluster
  893.                 -c "showEditorSetListType(\"lattice\")";
  894.             menuItem -l "Sculpt"
  895.                 -rb ($listType == "sculpt")
  896.                 -cl $listCluster
  897.                 -c "showEditorSetListType(\"sculpt\")";
  898.             menuItem -l "Wire"
  899.                 -rb ($listType == "wire")
  900.                 -cl $listCluster
  901.                 -c "showEditorSetListType(\"wire\")";
  902.             setParent -menu ..;
  903.         menuItem -l "Lights" -subMenu true AElightSubMenu;
  904.             menuItem -l "All Lights"
  905.                 -rb ($listType == "allLights")
  906.                 -cl $listCluster
  907.                 -c "showEditorSetListType(\"allLights\")";
  908.             menuItem -l "Spot Light"
  909.                 -rb ($listType == "spotLight")
  910.                 -cl $listCluster
  911.                 -c "showEditorSetListType(\"spotLight\")";
  912.             menuItem -l "Direction Light"
  913.                 -rb ($listType == "directionalLight")
  914.                 -cl $listCluster
  915.                 -c "showEditorSetListType(\"directionalLight\")";
  916.             menuItem -l "Point Light"
  917.                 -rb ($listType == "pointLight")
  918.                 -cl $listCluster
  919.                 -c "showEditorSetListType(\"pointLight\")";
  920.             menuItem -l "Ambient Light"
  921.                 -rb ($listType == "ambientLight")
  922.                 -cl $listCluster
  923.                 -c "showEditorSetListType(\"ambientLight\")";
  924.             menuItem -l "Volume Light"
  925.                 -rb ($listType == "volumeLight")
  926.                 -cl $listCluster
  927.                 -c "showEditorSetListType(\"volumeLight\")";
  928.             setParent -m ..;
  929.         menuItem -l "Shading" -subMenu true AEshadingSubMenu;
  930.             menuItem -l "Shading Groups"
  931.                 -rb ($listType == "shadingGrp")
  932.                 -cl $listCluster
  933.                 -c "showEditorSetListType(\"shadingGrp\")";
  934.             menuItem -d true;
  935.             menuItem -l "All Textures"
  936.                 -rb ($listType == "allTextures")
  937.                 -cl $listCluster
  938.                 -c "showEditorSetListType(\"allTextures\")";
  939.             menuItem -l "2D Textures"
  940.                 -rb ($listType == "textures2D")
  941.                 -cl $listCluster
  942.                 -c "showEditorSetListType(\"textures2D\")";
  943.             menuItem -l "3D Textures"
  944.                 -rb ($listType == "textures3D")
  945.                 -cl $listCluster
  946.                 -c "showEditorSetListType(\"textures3D\")";
  947.             menuItem -l "Environment Textures"
  948.                 -rb ($listType == "texturesEnv")
  949.                 -cl $listCluster
  950.                 -c "showEditorSetListType(\"texturesEnv\")";
  951.             setParent -m ..;
  952.     menu -l "Object" 
  953.     -pmc "showEditorCreateMenu" 
  954.     -familyImage "menuIconObject.xpm"
  955.     objectMenu;
  956.             // contents will be created when the menu is posted.
  957.     menu -l "Focus" 
  958.     -pmc "showEditorFocusMenu" 
  959.     -familyImage "menuIconFocus.xpm"
  960.     focusMenu;
  961.             // contents will be created when the menu is posted.
  962.     menu -l "Attributes" 
  963.     -familyImage "menuIconAdd.xpm"
  964.     addMenu;
  965.         menuItem -l "Add Attributes..." -c "showAddAttrWin";
  966.         menuItem -l "Delete Attributes..." -c "showDeleteAttrWin";
  967.         menuItem -l "Rename Attributes..." -c "showRenameAttrWin";
  968.  
  969.     menu -l "Help"
  970.     -helpMenu true
  971.     -pmc "showEditorHelpMenu"
  972.     AEhelpMenu;
  973. }
  974.  
  975.  
  976. // Expands the names of objects to their full path names
  977. //
  978. proc string[] AEexpandNames(string $array[])
  979. {
  980.     string    $retval[];
  981.     string    $buffer[];
  982.  
  983.     for ($i = 0; $i < size($array); $i++) {
  984.         $buffer = `ls -l $array[$i]`;
  985.         for ($j = 0; $j < size($buffer); $j++) {
  986.             $retval[size($retval)] = $buffer[$j];
  987.         }
  988.         clear $buffer;
  989.     }
  990.     return $retval;
  991. }
  992.  
  993. // Remove certain nodes (e.g. renderGlobals) from a list
  994. // so that user won't be able to tab to them
  995. // 
  996. proc string[] AEfilterUnwantedNodes( string $array[] )
  997. {   
  998.     string  $retVal[];
  999.     string  $nodeType;
  1000.     int     $count, 
  1001.             $i, 
  1002.             $j = 0;
  1003.     
  1004.     $count = size( $array );
  1005.     for ( $i = 0; $i < $count; $i++ )
  1006.     {   
  1007.         $nodeType = `nodeType $array[$i]`;
  1008.         if ( $nodeType != "renderGlobals" )
  1009.         {   
  1010.             $retVal[$j] = $array[$i];
  1011.             $j++;
  1012.         }
  1013.     }
  1014.     
  1015.     return $retVal;
  1016. }
  1017.  
  1018. // Determines a node's related nodes and returns them in a
  1019. // string array
  1020. //
  1021. proc string[] AEgetRelatedNodes( string $node )
  1022. {
  1023.     string    $rNodes[], $retval[], $tmpNodes[];
  1024.     string    $nodeNameType = `nodeType $node`;
  1025.     string    $relatedScript = ("AE"+$nodeNameType+"Related");
  1026.     
  1027.     if (`exists $relatedScript`) {
  1028.         $tmpNodes = `eval($relatedScript + " \"" + $node + "\"")`;
  1029.         $rNodes = `AEexpandNames($tmpNodes)`;
  1030.     } else {
  1031.         string $focusNode[];
  1032.         $tmpNodes = `defaultNavigation -ren -d $node`;
  1033.         $tmpNodes = `AEfilterUnwantedNodes( $tmpNodes )`;
  1034.         $rNodes = `AEexpandNames($tmpNodes)`;
  1035.         $focusNode[0] = `defaultNavigation -dwn -d $node`;
  1036.         clear $tmpNodes;
  1037.         $tmpNodes = `AEexpandNames($focusNode)`;
  1038.         $rNodes[size($rNodes)] = $tmpNodes[0];
  1039.     }
  1040.  
  1041.     // the first item in the return string array is the node itself
  1042.     //
  1043.     clear $tmpNodes;
  1044.     $tmpNodes[0] = $node;
  1045.     $retval = `AEexpandNames($tmpNodes)`;
  1046.  
  1047.     // need to go through the string array and remove unwanted
  1048.     // duplicates
  1049.     //
  1050.     for ($i = 0; $i < size($rNodes)-1; $i++) {
  1051.         $duplicated = false;
  1052.         for ($j = 0; $j < size($retval); $j++) {
  1053.             if ($rNodes[$i] == $retval[$j]) {
  1054.                 $duplicated = true;
  1055.                 break;
  1056.             }
  1057.         }
  1058.         if (!$duplicated) $retval[size($retval)] = $rNodes[$i];
  1059.     }
  1060.  
  1061.     // now search for the last item in the $retval for a duplicate
  1062.     //
  1063.     string $lastNode = $rNodes[size($rNodes)-1];
  1064.     $duplicated = false;
  1065.     for ($i = 0; $i < size($retval); $i++) {
  1066.         if ($lastNode == $retval[$i]) {
  1067.             $duplicated = true;
  1068.             break;
  1069.         }
  1070.     }
  1071.  
  1072.     if (!$duplicated) $retval[size($retval)] = $node;
  1073.     else $retval[size($retval)] = $lastNode;
  1074.  
  1075.     return $retval;
  1076.  
  1077. }
  1078.  
  1079.  
  1080. global proc AEbuildAllTabs( string $node )
  1081. //
  1082. //    Description:
  1083. //        Build the tabs and their contents for the node specified and
  1084. //        all the nodes related to the argument node.
  1085. //
  1086. {
  1087.     global string    $gAETabLayoutName;
  1088.     global string    $gRelatedNodes[];
  1089.     global string    $gAETabMarker[];
  1090.  
  1091.     //    Get all the nodes related to this node.
  1092.     //
  1093.     //    Note that the last item is a duplicate and is considered
  1094.     //    to be the default item whose tab should be selected in the
  1095.     //    Attribute Editor.
  1096.     //
  1097.     clear $gRelatedNodes;
  1098.     $gRelatedNodes = AEgetRelatedNodes( $node );
  1099.  
  1100.     //    The number of related nodes (and tabs to show) is one less than the 
  1101.     //    number of nodes returned from AEgetRelatedNodes().
  1102.     //    
  1103.     //    The last item in the related node array is a duplicate and
  1104.     //    is considered to be the default node to show in the Attribute
  1105.     //    Editor.
  1106.     //
  1107.     int     $nRNodes = size($gRelatedNodes)-1;
  1108.     int     $rNodeIndex = 0;
  1109.  
  1110.     //    Get the array position of the default node we want.
  1111.     //
  1112.     //    The default node is the very last one in the related node array.
  1113.     //    This node is duplicated in the list. For example, for a sphere 
  1114.     //    the related node array probably looks something like:
  1115.     //
  1116.     //    |nurbsSphere1
  1117.     //    |nurbsSphere1|nurbsSphereShape1
  1118.     //    makeNurbSphere1
  1119.     //    initialShadingGroup
  1120.     //    lambert1
  1121.     //    |nurbsSphere1|nurbsSphereShape1
  1122.     //
  1123.     //    Notice that the last node is the default node to show and it
  1124.     //    is a duplicate of the 2nd item in the array.
  1125.     //
  1126.     //    The following loop will determine where the last item is
  1127.     //    duplicated in the array.
  1128.     //
  1129.     //    This is the index of tab that should be selected after all
  1130.     //    the tabs are built.
  1131.     //
  1132.     for ($i = 0; $i < $nRNodes; $i++) {
  1133.         if ($gRelatedNodes[$nRNodes] == $gRelatedNodes[$i]) {
  1134.             $rNodeIndex = $i;
  1135.             break;
  1136.         }
  1137.     }
  1138.     //    Be sure to add 1 to this index because tab layout indecies are
  1139.     //    1-based while array indecies are 0-based.
  1140.     //
  1141.     $rNodeIndex++;
  1142.  
  1143.     //    The global array gAETabMarker keeps track of node types and for
  1144.     //    each node type the name of the last node of that type whose tab
  1145.     //    was selected in the Attribute Editor.
  1146.     //
  1147.     //    Check if the user has already brought up an AE of this
  1148.     //    nodeType and if so, what the last tab viewed was.
  1149.     //
  1150.     string $nodeTypeName = `nodeType $node`;
  1151.     string $lastViewedTab = "";
  1152.     for ($tabMarker in $gAETabMarker) {
  1153.         string $buffer[];
  1154.         tokenize($tabMarker,",",$buffer);
  1155.         string $tabMarkerType = $buffer[0];
  1156.         if ( $tabMarkerType == $nodeTypeName ) {
  1157.             $lastViewedTab = $buffer[1];
  1158.             break;
  1159.         }
  1160.     }
  1161.  
  1162.     // now, check if the new set of tabs has the one that was
  1163.     // last viewed (of the same type).  Don't count nodes
  1164.     // that are marked "internal", unless you have no other choice
  1165.     //
  1166.     int $prevSelectedTabIndex = -1;
  1167.     int $secondBestIndex = -1;
  1168.     if ( $lastViewedTab != "" && `objExists $lastViewedTab`) {
  1169.  
  1170.         string $lastViewedTabType = `nodeType $lastViewedTab`;
  1171.  
  1172.         //    Catch the condition where the argument node type is
  1173.         //    related to a node of the same type. When this happens
  1174.         //    we want to show the tab of the argument node in the AE
  1175.         //    rather than the tab of the related node.
  1176.         //    
  1177.         //    Say you have two nodes in your scene both of type lambert.
  1178.         //    You connect lambert2.outColor to lambert3.color. 
  1179.         //
  1180.         //    If you were to select lambert2 the Attribute Editor will
  1181.         //    remember (in gAETabMarker) that the last active tab of 
  1182.         //    type lambert was lambert2. Select lambert3 and we have
  1183.         //    the situation where lambert3 is related to lambert2, both
  1184.         //    have the same node type, and lambert2 was the last tab
  1185.         //    of this type shown in the AE. However, the user does not
  1186.         //    want lambert2 to be the selected tab. It should be lambert3.
  1187.         //
  1188.         if ($node != $lastViewedTab && $lastViewedTabType == $nodeTypeName) {
  1189.             $prevSelectedTabIndex = $rNodeIndex;
  1190.         }
  1191.  
  1192.         // Fix for BUG 143284, its more important to consider the name of
  1193.         // the last viewed tab, than the type of node last viewed. The
  1194.         // AE may flip between nodes if there is more than once choice
  1195.         // in the list of related nodes.
  1196.         //
  1197.         for ( $i = 0; $i < $nRNodes && $prevSelectedTabIndex == -1; $i++ ) {
  1198.             if ($lastViewedTab == $gRelatedNodes[$i]) {
  1199.                 string $rNodeType = `nodeType $gRelatedNodes[$i]`;
  1200.                 if ($rNodeType == $lastViewedTabType) {
  1201.                     $prevSelectedTabIndex = $i+1;
  1202.                 }
  1203.             }
  1204.         }
  1205.         for ( $i = 0; $i < $nRNodes && $prevSelectedTabIndex == -1; $i++ ) {
  1206.             string $rNodeType = `nodeType $gRelatedNodes[$i]`;
  1207.             if ( $rNodeType == $lastViewedTabType) {
  1208.                 $secondBestIndex = $i+1;
  1209.                 // if the object has an "intemediateObject" attribute...
  1210.                 if ( `attributeQuery -ex -node $gRelatedNodes[$i] intermediateObject` ){
  1211.                     // then it must be FALSE to allow this object on the list
  1212.                     if ( !`getAttr ($gRelatedNodes[$i] + ".intermediateObject")` ){
  1213.                         $prevSelectedTabIndex = $i+1;
  1214.                     }
  1215.                 } else { // if it has no such attribute, we can accept it.
  1216.                     $prevSelectedTabIndex = $i+1;
  1217.                 }
  1218.             }
  1219.         }
  1220.     }
  1221.     
  1222.     // If we had no first choice, use the second choice
  1223.     //
  1224.     if ( $prevSelectedTabIndex == -1 ) $prevSelectedTabIndex = $secondBestIndex;
  1225.  
  1226.     // set the selected tab index
  1227.     //
  1228.     if ( $prevSelectedTabIndex == -1 ) {
  1229.         // no previously recorded selected tab for this nodeType
  1230.         // so use the default
  1231.         $prevSelectedTabIndex = $rNodeIndex;
  1232.     }
  1233.  
  1234.  
  1235.     // now, actually rebuild the tabs
  1236.     //
  1237.     setParent $gAETabLayoutName;
  1238.  
  1239.     string  $currentTabs[] = `tabLayout -q -ca $gAETabLayoutName`;
  1240.     int     $nCurrentTabs = size($currentTabs);
  1241.  
  1242.     int     $i;
  1243.     string    $label;
  1244.     if ($nRNodes >= $nCurrentTabs) {
  1245.         for ( $i = 0; $i < $nCurrentTabs; $i++ ) {
  1246.             $label = `AEnoSlash($gRelatedNodes[$i])`;
  1247.             // swap these tabs
  1248.             tabLayout -e
  1249.                 -tabLabel ("formTab"+$i) $label
  1250.                 $gAETabLayoutName;
  1251.             nameField -e
  1252.                 -o $gRelatedNodes[$i]
  1253.                 -ncc ("AErenameChangedCommand " + $i)
  1254.                 ("tabNameField"+$i);
  1255.         }
  1256.         for ( $i = $nCurrentTabs; $i < $nRNodes; $i++ ) {
  1257.             // create new tabs
  1258.             $label = `AEnoSlash($gRelatedNodes[$i])`;
  1259.             formLayout ("formTab"+$i);
  1260.                 nameField
  1261.                     -vis false
  1262.                     -h 5
  1263.                     -o $gRelatedNodes[$i]
  1264.                     -ncc ("AErenameChangedCommand " + $i)
  1265.                     ("tabNameField"+$i);
  1266.             setParent ..;
  1267.             tabLayout -e
  1268.                 -tabLabel ("formTab"+$i) $label
  1269.                 $gAETabLayoutName;
  1270.         }
  1271.     } else {
  1272.         for ( $i = 0; $i < $nRNodes; $i++ ) {
  1273.             // swap these tabs
  1274.             $label = `AEnoSlash($gRelatedNodes[$i])`;
  1275.             tabLayout -e
  1276.                 -tabLabel ("formTab"+$i) $label
  1277.                 $gAETabLayoutName;
  1278.             nameField -e
  1279.                 -o $gRelatedNodes[$i]
  1280.                 -ncc ("AErenameChangedCommand " + $i)
  1281.                 ("tabNameField"+$i);
  1282.         }
  1283.         for ( $i = $nRNodes; $i < $nCurrentTabs; $i++ ) {
  1284.             // delete these tabs
  1285.             deleteUI -layout $currentTabs[$i];
  1286.         }
  1287.     }
  1288.  
  1289.     // select the tab which was duplicated
  1290.     tabLayout -e -selectTabIndex $prevSelectedTabIndex $gAETabLayoutName;
  1291. }
  1292.  
  1293. global proc int AEpresetMenuForDir( int $numPresetsInMenu[], // arrays pass by reference
  1294.                                     string $ppath, 
  1295.                                     string $node, 
  1296.                                     int $callWithFullPath )
  1297. {
  1298.     int $itemLimit = 30;
  1299.     int $numItems = 0;
  1300.     if( `file -q -ex $ppath` ){
  1301.         string $files;
  1302.         if( `about -nt` ){
  1303.             $files = `system ( "dir /b \"" + $ppath + "\""  )`;
  1304.         } else if (`about -irix` || `about -linux`) {
  1305.             $files = `system ( "ls " + $ppath )`;
  1306.         }else if (`about -mac`){
  1307.             string $filesList[];
  1308.             int $i;
  1309.             
  1310.             $filesList = `getFileList -folder $ppath`;
  1311.             for($i = 0; $i < size($filesList); $i++){
  1312.                 $files = $files + $filesList[$i] + "\n";
  1313.             }
  1314.         } else {
  1315.             warning( "Operating system is not recognized." );
  1316.         }
  1317.     
  1318.         string $fileList[];
  1319.         $numTokens = tokenize( $files, $fileList );
  1320.         // create Directory for current node type
  1321.         if ($numTokens > 0 && !($numTokens == 1 && $fileList[0] == "unknown")) {
  1322.             string $file;
  1323.             for ( $file in $fileList ) {
  1324.                 // only show .mel files
  1325.                 if(  size( match( ".mel", $file ) ) ){
  1326.                     string $presetName = `substitute ".mel" $file ""`;
  1327.                     string $menuCommand = ("applyAttrPreset \"" + $node + "\" \"" );
  1328.                     if( $callWithFullPath ){
  1329.                         $menuCommand = $menuCommand + $ppath + "/" + $file + "\" ";
  1330.                     } else {
  1331.                         $menuCommand = $menuCommand + $presetName + "\" ";
  1332.                     }
  1333.                     $numItems++;
  1334.                     menuItem
  1335.                     -subMenu true
  1336.                     -l ($presetName);
  1337.                         menuItem
  1338.                             -l "replace" 
  1339.                             -c ($menuCommand + "1");
  1340.                         menuItem
  1341.                             -l "blend 90%" 
  1342.                             -c ($menuCommand + ".9");
  1343.                         menuItem
  1344.                             -l "blend 75%" 
  1345.                             -c ($menuCommand + ".7");
  1346.                         menuItem
  1347.                             -l "blend 50%" 
  1348.                             -c ($menuCommand + ".51");
  1349.                         menuItem
  1350.                             -l "blend 25%" 
  1351.                             -c ($menuCommand + ".25");
  1352.                         menuItem
  1353.                             -l "blend 10%" 
  1354.                             -c ($menuCommand + ".1");
  1355.                     setParent -menu ..;
  1356.     
  1357.                     $numPresetsInMenu[0] = $numPresetsInMenu[0] + 1;
  1358.  
  1359.                     // If there are more than $itemLimit presets
  1360.                     // we need to split the menu into submenus 
  1361.                     // - otherwise it does not fit on the screen.
  1362.                     //
  1363.                     if( $numPresetsInMenu[0] >= $itemLimit ) {
  1364.                         menuItem -subMenu true -l "more ... ";
  1365.                         $numPresetsInMenu[0] = 0;
  1366.                     }
  1367.                 }
  1368.             }
  1369.         }
  1370.     }
  1371.  
  1372.     return $numItems;
  1373.  
  1374. }
  1375.  
  1376. global proc AEshowPresetMenu( string $presetMenu, string $node )
  1377. {
  1378.     setParent -menu $presetMenu;
  1379.  
  1380.     int $i = 0;
  1381.     string $mI;
  1382.  
  1383.     popupMenu -e -deleteAllItems $presetMenu;
  1384.  
  1385.     string $ntype = `nodeType $node`;
  1386.  
  1387.     menuItem
  1388.         -l ("Save " + $ntype + " Preset...")
  1389.         -c ("saveAttrPresetWin " + $node);
  1390.     menuItem
  1391.         -l ("Edit Presets...")
  1392.         -c ("attrPresetEditWin " + $ntype);
  1393.  
  1394.     menuItem -d true;
  1395.     int $numPresets = 0;
  1396.     int $numPresetsInMenu[] = { 0 };
  1397.     int $numNonLocalPresets = 0;
  1398.  
  1399.     // first show the released presets
  1400.     string $fpath = `getenv "MAYA_LOCATION"`;
  1401.     $fpath = $fpath + "/presets/attrPresets/" + $ntype;
  1402.     $numPresets = AEpresetMenuForDir( $numPresetsInMenu, $fpath, $node, 1);
  1403.  
  1404.     $numNonLocalPresets += $numPresets;
  1405.     if($numPresets > 0)
  1406.         menuItem -d true;
  1407.  
  1408.     // then show any presets specified by MAYA_PRESET_PATH 
  1409.     // each entry in the path points at equivalents to the presets directory
  1410.     string $mayaPresetPath = `getenv MAYA_PRESET_PATH`;
  1411.     string $presetPaths[];
  1412.     if (`about -nt`) 
  1413.         tokenize $mayaPresetPath ";" $presetPaths;
  1414.     else
  1415.         tokenize $mayaPresetPath ":" $presetPaths;
  1416.     for($presetPath in $presetPaths) {
  1417.         $fpath = $presetPath;
  1418.         $fpath = $fpath + "/attrPresets/" + $ntype;
  1419.         $numPresets = AEpresetMenuForDir( $numPresetsInMenu, $fpath, $node, 1);
  1420.  
  1421.         $numNonLocalPresets += $numPresets;
  1422.         if($numPresets > 0)
  1423.             menuItem -d true;
  1424.     }
  1425.     menuItem -d true;
  1426.  
  1427.     // finally show any local presets that the user has created
  1428.     string $ppath = `internalVar -userPrefDir`;
  1429.     $ppath = substitute( "prefs", $ppath, "presets/attrPresets");
  1430.     $ppath  = $ppath + $ntype; 
  1431.     AEpresetMenuForDir( $numPresetsInMenu, $ppath, $node, 0);
  1432. }
  1433.  
  1434. proc AEattachTabHeader (string $node)
  1435. {
  1436.     string $parent = `setParent AEnodeNameHeaderLayout`;
  1437.     string $ntype = `nodeType $node`;
  1438.     text -e -label ($ntype + ":") AEnodeTypeLabel;
  1439.  
  1440.     nameField -e
  1441.         -object $node
  1442.         AEnodeNameField;
  1443.  
  1444.     // Setup the backward
  1445.     symbolButton -e
  1446.         -c ("AEpropagateMenuCB -backward \"\" \""+$node+"\"")
  1447.         AEbackwardButton;
  1448.     string $backwardMenu = $parent+"|AEbackwardButton|menu";
  1449.     popupMenu -e
  1450.         -pmc ("AEpropagateMenuCB -backward "+$backwardMenu+" \""+$node+"\"")
  1451.         $backwardMenu;
  1452.  
  1453.     // Setup the forward
  1454.     symbolButton -e
  1455.         -c ("AEpropagateMenuCB -forward \"\" \""+$node+"\"")
  1456.         AEforwardButton;
  1457.     string $forwardMenu = $parent+"|AEforwardButton|menu";
  1458.     popupMenu -e
  1459.         -pmc ("AEpropagateMenuCB -forward "+$forwardMenu+" \""+$node+"\"")
  1460.         $forwardMenu;
  1461.  
  1462.     if( 0 == isValidAttrPresetNodeType( $ntype )){
  1463.         button -e -en 0 AEpresetButton;
  1464.     } else {
  1465.         int $hasPresets = false;
  1466.  
  1467.         // first check the local and release presets
  1468.         string $ppath = `internalVar -userPrefDir`;
  1469.         $ppath = substitute( "prefs", $ppath, "presets/attrPresets");
  1470.         $ppath  = $ppath + $ntype; 
  1471.         string $fpath = `getenv "MAYA_LOCATION"`;
  1472.         $fpath = $fpath + "/presets/attrPresets/" + $ntype;
  1473.         if( `file -q -ex $ppath` || `file -q -ex $fpath` )
  1474.             $hasPresets = true;
  1475.  
  1476.         // if we didnt find any, see if the preset path has some
  1477.         if(!$hasPresets) {
  1478.             // MAYA_PRESET_PATH points at equivalents to the presets directory
  1479.             string $mayaPresetPath = `getenv MAYA_PRESET_PATH`;
  1480.             string $presetPaths[];
  1481.             if (`about -nt`) 
  1482.                 tokenize $mayaPresetPath ";" $presetPaths;
  1483.             else
  1484.                 tokenize $mayaPresetPath ":" $presetPaths;
  1485.             for($presetPath in $presetPaths) {
  1486.                 $fpath = $presetPath;
  1487.                 $fpath = $fpath + "/attrPresets/" + $ntype;
  1488.                 if( `file -q -ex $fpath` ) {
  1489.                     $hasPresets = true;
  1490.                     break;
  1491.                 }
  1492.             }
  1493.         }
  1494.  
  1495.         int $enable = true;
  1496.         if (`about -evalVersion`) $enable = false;
  1497.  
  1498.         // if any presets exist for node type, indicate with a "*"
  1499.         if( $hasPresets ){
  1500.             button -e -enable $enable -l "Presets*" -w 60 -h 20 AEpresetButton;
  1501.         } else {
  1502.             button -e -enable $enable -l "Presets"  -w 60 -h 20 AEpresetButton;
  1503.         }
  1504.     }
  1505.  
  1506.     string $presetMenu = $parent+"|AEpresetButton|menu";
  1507.     popupMenu -e
  1508.         -pmc ("commitAENotes($gAECurrentTab);AEshowPresetMenu \""+$presetMenu+"\" \""+$node+"\"")
  1509.         $presetMenu;
  1510.  
  1511.     // Setup the Focus button
  1512.     button -e
  1513.         -c ("commitAENotes($gAECurrentTab);showEditor \"" + $node + "\"")
  1514.         AEfocusButton;
  1515.  
  1516.     setParent ..;
  1517.  
  1518. }
  1519.  
  1520.  
  1521. proc AEattachSelectButton( string $node )
  1522. {
  1523.     // Setup the Select button
  1524.     setParent AEselectAndCloseButtonLayout;
  1525.     button -e
  1526.         -c ("commitAENotes($gAECurrentTab);select \""+$node+"\"")
  1527.         AEselectButton;
  1528. }
  1529.  
  1530.  
  1531. global proc AEbuildControls()
  1532. {
  1533.     global string    $gAETabLayoutName;
  1534.     global string    $gAEControlLayoutName;
  1535.     global string    $gLastViewedAEType;
  1536.     global string    $gRelatedNodes[];
  1537.     global string    $gAECurrentTab;
  1538.     global string    $gAEPrevCurrentTab;
  1539.     global string    $gAETabMarker[];
  1540.  
  1541.     // get the tab info
  1542.     //
  1543.     string $tab = `tabLayout -q -selectTab $gAETabLayoutName`;
  1544.     int $tabIndex = `tabLayout -q -selectTabIndex $gAETabLayoutName`;
  1545.     string $node = $gRelatedNodes[$tabIndex-1];
  1546.  
  1547.     if (!`objExists $node`) return;
  1548.  
  1549.     string $nodeTypeForm = ("AttrEd"+`nodeType $node`+"FormLayout");
  1550.     string $focusNode = $gRelatedNodes[0];
  1551.     string $focusNodeType = `nodeType $focusNode`;
  1552.  
  1553.     // build the formLayout if it doesn't already exist
  1554.     //
  1555.     setParent $gAEControlLayoutName;
  1556.     if (!`formLayout -exists $nodeTypeForm`) {
  1557.         formLayout -vis false $nodeTypeForm;
  1558.         setParent ..;
  1559.     }
  1560.  
  1561.     // create the attribute editor
  1562.     //
  1563.     createEditor -qfd $nodeTypeForm $node;
  1564.  
  1565.     formLayout -e -vis true $nodeTypeForm;
  1566.  
  1567.     // attach everything
  1568.     //
  1569.     AEattachEditor $nodeTypeForm;
  1570.     AEattachTabHeader $node;
  1571.     AEattachSelectButton($node);
  1572.  
  1573.     $gLastViewedAEType = `nodeType $node`;
  1574.  
  1575.     // keep track of the tab for this node
  1576.     //
  1577.     int    $found = false;
  1578.     for ( $i = 0; $i < size($gAETabMarker); $i++ ) {
  1579.         string $buffer[];
  1580.         tokenize($gAETabMarker[$i],",",$buffer);
  1581.         string $tabMarker = $buffer[0];
  1582.         if ( $tabMarker == $focusNodeType) {
  1583.             $gAETabMarker[$i] = $focusNodeType+ "," + $node;
  1584.             $found = true;
  1585.             break;
  1586.         }
  1587.     }
  1588.     if (!$found) {
  1589.         // add this focusNodeType to the $gAETabMarker
  1590.         //
  1591.         $gAETabMarker[size($gAETabMarker)] = $focusNodeType+","+$node;
  1592.     }
  1593.  
  1594.     // display the built AE
  1595.     //
  1596.     tabLayout -e -st $nodeTypeForm $gAEControlLayoutName;
  1597.     $gAEPrevCurrentTab = $gAECurrentTab;
  1598.     $gAECurrentTab = $node;
  1599.  
  1600.     // Update any Notes 
  1601.     {
  1602.         // Try committing the previously showing node before showing this AE.
  1603.         // This will apply whatever was in the Notes section to the
  1604.         // previously showing node.
  1605.         //
  1606.         // Checking gAEPrevCurrentTab !="" avoids very first time AE is opened.
  1607.         // Checking gAEPrevCurrentTab != gAECurrentTab avoids redundant commits.
  1608.         //
  1609.         killScriptJobAENotes();
  1610.         if( ($gAEPrevCurrentTab != "") && 
  1611.             ($gAEPrevCurrentTab != $gAECurrentTab) ) {
  1612.             commitAENotes($gAEPrevCurrentTab );
  1613.         }
  1614.     
  1615.         // Update the AE notes section to display the notes of the
  1616.         // current node.
  1617.         // 
  1618.         updateAENotes( $gAECurrentTab, "notes" );
  1619.         setupScriptJobAENotes( $gAECurrentTab, "notes" );
  1620.     }
  1621. }
  1622.  
  1623.  
  1624. global proc AErenameChangedCommand( int $nameFieldIndex )
  1625. {
  1626.     global string    $gAETabLayoutName;
  1627.     global string    $gAEFocusNode;
  1628.     global string    $gAttributeEditorWindowName;
  1629.     global string    $gAECurrentTab;
  1630.  
  1631.     // first, find the tab index to the current tab
  1632.     //
  1633.     int    $currentTabIndex = `tabLayout -q -sti $gAETabLayoutName`;
  1634.  
  1635.     // rebuild the tabs    
  1636.     //
  1637.     string $node = `nameField -q -object "tabNameField0"`;
  1638.     AEbuildAllTabs $node;
  1639.  
  1640.     // update the title bar and focus node, if the attribute
  1641.     // editor is in a separate window
  1642.     //
  1643.     if ( `window -exists $gAttributeEditorWindowName` ){
  1644.         $gAEFocusNode = $node;
  1645.         string $tokens[];
  1646.         tokenize($node,"|",$tokens);
  1647.         $node = $tokens[size($tokens)-1];
  1648.         window -e
  1649.             -title ("Attribute Editor: "+$node)
  1650.             $gAttributeEditorWindowName;
  1651.     }
  1652.  
  1653.     // now reselect the original tab
  1654.     //
  1655.     tabLayout -e -sti $currentTabIndex $gAETabLayoutName;
  1656.  
  1657.     // build this tab's controls
  1658.     //
  1659.     AEbuildControls;
  1660.  
  1661.     // Update the Notes section with the node that
  1662.     // is the front tab.  This is not necessarily the
  1663.     // selected object.
  1664.     {
  1665.         updateAENotes( $gAECurrentTab, "notes");
  1666.     }
  1667.  
  1668. }
  1669.  
  1670.  
  1671. global proc AEbuildTabHeader ( string $node, string $parent )
  1672. {
  1673.     setParent $parent;
  1674.     formLayout AEnodeNameHeaderLayout;
  1675.     global int $gTextColumnWidthIndex;
  1676.     global int $gAENameTextFieldIndex;
  1677.  
  1678.         text AEnodeTypeLabel;
  1679.  
  1680.         nameField AEnodeNameField;
  1681.  
  1682.         symbolButton -i "inArrow.xpm"
  1683.             -annotation "LMB: Go to input connection; RMB: Show all input connections to choose from"
  1684.             -w 45
  1685.             -h 20
  1686.             AEforwardButton;
  1687.         popupMenu menu;
  1688.         setParent -m ..;
  1689.  
  1690.         symbolButton -i "outArrow.xpm"
  1691.             -annotation "LMB: Go to output connection; RMB: Show all output connections to choose from"
  1692.             -w 45
  1693.             -h 20
  1694.             AEbackwardButton;
  1695.         popupMenu menu;
  1696.         setParent -m ..;
  1697.  
  1698.         button
  1699.             -annotation "Set attribute editor focus to this node"
  1700.             -al center
  1701.             -w 60 
  1702.             -h 20 
  1703.             -l "Focus"
  1704.             AEfocusButton;
  1705.  
  1706.         int $enable = true;
  1707.         if (`about -evalVersion`) $enable = false;
  1708.         button
  1709.             -annotation "Attribute presets for this node"
  1710.             -al center
  1711.             -w 60
  1712.             -h 20
  1713.             -l "Presets"
  1714.             -enable $enable
  1715.             AEpresetButton;
  1716.         popupMenu -button 1 menu;
  1717.         setParent -m ..;
  1718.  
  1719.     setParent ..;
  1720.    
  1721.     formLayout -e
  1722.         -aof AEnodeTypeLabel right (-$gTextColumnWidthIndex)
  1723.         -af AEnodeTypeLabel top 0
  1724.         -af AEnodeTypeLabel bottom 0
  1725.         -an AEnodeTypeLabel left
  1726.         -ac AEnodeNameField left 5 AEnodeTypeLabel
  1727.         -aoc AEnodeNameField right (-$gAENameTextFieldIndex) AEnodeTypeLabel
  1728.         -af AEnodeNameField top 9
  1729.         -af AEnodeNameField bottom 9
  1730.         -af AEforwardButton top 0
  1731.         -an AEforwardButton bottom
  1732.         -ac AEforwardButton left 5 AEnodeNameField
  1733.         -an AEforwardButton right
  1734.         -ac AEbackwardButton top 2 AEforwardButton
  1735.         -an AEbackwardButton bottom
  1736.         -ac AEbackwardButton left 5 AEnodeNameField
  1737.         -an AEbackwardButton right
  1738.         -ac AEfocusButton left 5 AEforwardButton
  1739.         -af AEfocusButton top 0
  1740.         -an AEfocusButton bottom 
  1741.         -an AEfocusButton right
  1742.         -ac AEpresetButton top 2 AEfocusButton
  1743.         -an AEpresetButton bottom 
  1744.         -ac AEpresetButton left 5 AEforwardButton 
  1745.         -an AEpresetButton right
  1746.         AEnodeNameHeaderLayout;
  1747.  
  1748.     if ($node != "")
  1749.         AEattachTabHeader($node);
  1750. }
  1751.  
  1752.  
  1753.  
  1754. global proc createAEWindowContents( string $parent, string $node, string $listType )
  1755. {
  1756.     global string    $gAttributeEditorWindowName;
  1757.     global int        $gStandardWindowWidthIndex;
  1758.     global string    $gAENothingSelectedLayout;
  1759.     global string     $gAEMenuBarLayoutName;
  1760.     global string    $gAERootLayoutName;
  1761.     global string    $gAERootPaneLayoutName;
  1762.     global string    $gAEBaseLayoutName;
  1763.     global string    $gAEHeaderLayoutName;
  1764.     global string    $gAETabLayoutName;
  1765.     global string    $gAEControlLayoutName;
  1766.     global int        $gAutoUpdateAttrEdFlag;
  1767.     global string    $gLastViewedAEType;
  1768.     global string    $gRelatedNodes[];
  1769.     global string    $gAETabMarker[];
  1770.     global int        $gAESelectionScriptJob;
  1771.     global int        $gAEConstructionScriptJob;
  1772.  
  1773.     // reset global variables
  1774.     //
  1775.     resetAEGlobalVariables(); // in resetAE.mel
  1776.  
  1777.     setUITemplate -pushTemplate attributeEditorTemplate;
  1778.  
  1779.     setParent $parent;
  1780.  
  1781.     int $inWindow = ( $parent == "AEWindow" );
  1782.  
  1783.     //    Need a menuBarLayout here
  1784.  
  1785.     menuBarLayout $gAEMenuBarLayoutName;
  1786.  
  1787.     formLayout $gAERootLayoutName;
  1788.         
  1789.         // Add a separator to fix the window width
  1790.         // This is necessary ONLY to having the AE appear
  1791.         // the correct width  within the main Maya window
  1792.         // on NT.  This only became necessary with
  1793.         // the addition of a paneLayout to contain
  1794.         // the attributes and the Notes section.
  1795.         //
  1796.         separator -style none -h 1 -width 425;
  1797.  
  1798.         formLayout $gAENothingSelectedLayout;
  1799.             text
  1800.                 -l "Make a selection to view attributes."
  1801.                 AEnothingSelectedText;
  1802.             formLayout -e
  1803.                 -af AEnothingSelectedText left 5
  1804.                 -af AEnothingSelectedText top 5
  1805.                 -an AEnothingSelectedText right
  1806.                 -an AEnothingSelectedText bottom 
  1807.                 $gAENothingSelectedLayout;
  1808.         setParent ..;
  1809.  
  1810.         // Create a pane layout with a top pane and
  1811.         // a bottom pane.  The top pane will show
  1812.         // the attribiutes.  The bottom pane will
  1813.         // have a section for editing Notes.
  1814.         //
  1815.  
  1816.         // Set the pane size based on option var
  1817.         // Note that if the option var does not exist
  1818.         // yet, we don't overwrite it here.  See showEditor()
  1819.         //
  1820.         int $paneSize = 85;
  1821.         if ( `optionVar -exists "attrEdPaneRatio"` ) {
  1822.             $paneSize = `optionVar -q "attrEdPaneRatio"`;
  1823.         }
  1824.         paneLayout -configuration "horizontal2" 
  1825.             -paneSize 1 100 $paneSize
  1826.             -paneSize 2 100 (100 - $paneSize) 
  1827.             $gAERootPaneLayoutName;
  1828.  
  1829.             formLayout $gAEBaseLayoutName;
  1830.     
  1831.                 formLayout $gAEHeaderLayoutName;
  1832.     
  1833.                     tabLayout
  1834.                         -preSelectCommand "AEbuildControls"
  1835.                         $gAETabLayoutName;
  1836.                           setParent ..;
  1837.     
  1838.                 setParent ..;
  1839.  
  1840.                 // attach the header formLayout
  1841.                 //
  1842.                 formLayout -e
  1843.                     -af $gAETabLayoutName top 10
  1844.                     -af $gAETabLayoutName left 0
  1845.                     -af $gAETabLayoutName right 0
  1846.                     -af $gAETabLayoutName bottom 0
  1847.                     $gAEHeaderLayoutName;
  1848.     
  1849.                 AEbuildTabHeader($node,`setParent -q`);
  1850.     
  1851.                 tabLayout -tabsVisible false $gAEControlLayoutName;
  1852.                 setParent ..;
  1853.     
  1854.             setParent ..;
  1855.     
  1856.             // attach the base formLayout
  1857.             //
  1858.             formLayout -e
  1859.                 -af $gAEHeaderLayoutName left 0
  1860.                 -af $gAEHeaderLayoutName top 0
  1861.                 -af $gAEHeaderLayoutName right 0
  1862.                 -an $gAEHeaderLayoutName bottom
  1863.                 -af AEnodeNameHeaderLayout left 0
  1864.                 -ac AEnodeNameHeaderLayout top 5 $gAEHeaderLayoutName
  1865.                 -af AEnodeNameHeaderLayout right 0
  1866.                 -an AEnodeNameHeaderLayout bottom
  1867.                 -af $gAEControlLayoutName left 0
  1868.                 -ac $gAEControlLayoutName top 5 AEnodeNameHeaderLayout
  1869.                 -af $gAEControlLayoutName right 0
  1870.                 -af $gAEControlLayoutName bottom 0
  1871.                 $gAEBaseLayoutName;
  1872.  
  1873.             // add controls for editing Notes
  1874.             //
  1875.             formLayout AEaddOrEditNotesLayout;
  1876.                 text -font "boldLabelFont"
  1877.                     -align "left" 
  1878.                     -l "  Notes:" AENotesTextLabel;
  1879.                 text -font "boldLabelFont"
  1880.                     -align "right" 
  1881.                     -l "*" AENotesTextLabel2;
  1882.                 scrollField -wordWrap true -editable true
  1883.                                 -text "" AENotesScrollField;
  1884.             setParent..;
  1885.     
  1886.             formLayout -edit 
  1887.                 -af AENotesTextLabel top 0
  1888.                 -an AENotesTextLabel right
  1889.                 -an AENotesTextLabel bottom
  1890.                 -af AENotesTextLabel left 0 
  1891.  
  1892.                 -af AENotesTextLabel2 top 0
  1893.                 -an AENotesTextLabel2 right
  1894.                 -an AENotesTextLabel2 bottom
  1895.                 -ac AENotesTextLabel2 left 0 AENotesTextLabel
  1896.  
  1897.                 -af AENotesScrollField left 0
  1898.                 -ac AENotesScrollField top 0 AENotesTextLabel
  1899.                 -af AENotesScrollField right 0
  1900.                 -af AENotesScrollField bottom 0
  1901.                     AEaddOrEditNotesLayout;
  1902.  
  1903.         setParent ..;        // for the paneLayout
  1904.  
  1905.         // Add a callback when the pane is resized
  1906.         //
  1907.         paneLayout -e -smc "paneSizeAttrEd();" $gAERootPaneLayoutName;
  1908.  
  1909.  
  1910.         // add buttons for Select, Load, Copy Tab and Close
  1911.         //
  1912.         formLayout -nd 100 AEselectAndCloseButtonLayout;
  1913.             button
  1914.                 -annotation "Select currently displayed node"
  1915.                 -al center
  1916.                 -l "Select"
  1917.                 AEselectButton;
  1918.             button
  1919.                 -annotation "Load current selection into the attribute editor"
  1920.                 -l "Load Attributes"
  1921.                 -c "commitAENotes($gAECurrentTab);editSelected"
  1922.                 AEreloadButton;
  1923.  
  1924.             button
  1925.                 -annotation "Copy the contents of the current tab into a new floating window"
  1926.                 -l "Copy Tab"
  1927.                 -c "commitAENotes($gAECurrentTab);copyAEWindow"
  1928.                 AEcopyButton;
  1929.             button
  1930.                 -annotation "Close the attribute editor"
  1931.                 -l "Close"
  1932.                 -c ("commitAENotes($gAECurrentTab);window -e -vis 0 " + $gAttributeEditorWindowName)
  1933.                 AEcloseButton;
  1934.         setParent ..;
  1935.  
  1936.         if( $inWindow ) {
  1937.             //    The AE is in a window - setup the close, 
  1938.             //    select, and reload buttons
  1939.  
  1940.             formLayout -e
  1941.                 -af AEselectButton top 5
  1942.                 -ap AEselectButton right 2 25
  1943.                 -af AEselectButton left 5
  1944.                 -af AEselectButton bottom 5
  1945.                 
  1946.                 -af AEreloadButton top 5
  1947.                 -ap AEreloadButton left 3 25
  1948.                 -ap AEreloadButton right 2 50
  1949.                 -af AEreloadButton bottom 5
  1950.                 
  1951.                 -af AEcopyButton top 5
  1952.                 -ap AEcopyButton left 3 50
  1953.                 -ap AEcopyButton right 2 75
  1954.                 -af AEcopyButton bottom 5
  1955.                 
  1956.                 -af AEcloseButton top 5
  1957.                 -ap AEcloseButton left 3 75
  1958.                 -af AEcloseButton right 5
  1959.                 -af AEcloseButton bottom 5
  1960.                 AEselectAndCloseButtonLayout;
  1961.                 button -e -vis true AEcloseButton;
  1962.         } else {
  1963.             //    The AE is in the main window - setup the 
  1964.             //    select and reload buttons only
  1965.  
  1966.             formLayout -e
  1967.                 -af AEselectButton top 1
  1968.                 -ap AEselectButton right 1 33
  1969.                 -af AEselectButton left 1
  1970.                 -af AEselectButton bottom 2
  1971.                 
  1972.                 -af AEreloadButton top 1
  1973.                 -ap AEreloadButton left 1 33 
  1974.                 -ap AEreloadButton right 1 67
  1975.                 -af AEreloadButton bottom 2
  1976.  
  1977.                 -af AEcopyButton top 1
  1978.                 -ap AEcopyButton left 1 67
  1979.                 -af AEcopyButton right 1
  1980.                 -af AEcopyButton bottom 2
  1981.                 
  1982.                 AEselectAndCloseButtonLayout;
  1983.  
  1984.                 //    Bug fix #146360.
  1985.                 //    Unmanage this widget so it does not affect the size
  1986.                 //    of the rest of the layout. I believe this is what was
  1987.                 //    causing the Attribute Editor in the main window to be 
  1988.                 //    extra wide.
  1989.                 //
  1990.                 button -e -manage false AEcloseButton;
  1991.         }
  1992.             
  1993.     setParent ..;
  1994.  
  1995.     // now attach the root
  1996.     //
  1997.     formLayout -e
  1998.         -af $gAENothingSelectedLayout left 0
  1999.         -af $gAENothingSelectedLayout top 0
  2000.         -af $gAENothingSelectedLayout right 0
  2001.         -ac $gAENothingSelectedLayout bottom 0 AEselectAndCloseButtonLayout
  2002.         -af $gAERootPaneLayoutName top 0
  2003.         -af $gAERootPaneLayoutName left 0
  2004.         -af $gAERootPaneLayoutName right 0
  2005.         -ac $gAERootPaneLayoutName bottom 0 AEselectAndCloseButtonLayout
  2006.         -an AEselectAndCloseButtonLayout top
  2007.         -af AEselectAndCloseButtonLayout left 0
  2008.         -af AEselectAndCloseButtonLayout right 0
  2009.         -af AEselectAndCloseButtonLayout bottom 0
  2010.         $gAERootLayoutName;
  2011.  
  2012.     // create the process to auto-update the attribute editor
  2013.     //
  2014.     $gAutoUpdateAttrEdFlag = ($listType == "auto");
  2015.  
  2016.     $gAESelectionScriptJob = `scriptJob -protected
  2017.                             -parent $gAEMenuBarLayoutName
  2018.                             -event "SelectionChanged" "autoUpdateAttrEd"`;
  2019.     $gAEConstructionScriptJob = `scriptJob -protected
  2020.                             -parent $gAEMenuBarLayoutName
  2021.                             -event "constructionHistoryChanged" "autoUpdateAttrEd"`;
  2022.  
  2023.     // build the menuBarLayouts menubar
  2024.     //
  2025.     buildAEMenus $gAERootLayoutName;
  2026.     if ( $listType != "auto" ) {
  2027.         // enable all of the other menu items
  2028.         menuItem -e -en true AEreloadSelectedMenuItem;
  2029.         menuItem -e -en true AEselectedItemsMenuItem;
  2030.         menuItem -e -en true AEdynamicsSubMenu;
  2031.         menuItem -e -en true AEkinematicsSubMenu;
  2032.         menuItem -e -en true AEdeformersSubMenu;
  2033.         menuItem -e -en true AElightSubMenu;
  2034.         menuItem -e -en true AEshadingSubMenu;
  2035.     } else {
  2036.         // disable all of the other menu items
  2037.         menuItem -e -en false AEreloadSelectedMenuItem;
  2038.         menuItem -e -en false AEselectedItemsMenuItem;
  2039.         menuItem -e -en false AEdynamicsSubMenu;
  2040.         menuItem -e -en false AEkinematicsSubMenu;
  2041.         menuItem -e -en false AEdeformersSubMenu;
  2042.         menuItem -e -en false AElightSubMenu;
  2043.         menuItem -e -en false AEshadingSubMenu;
  2044.     }
  2045.     if ( $listType == "auto" || $listType == "selected" ) {
  2046.         menu -e -l "Selected" objectMenu;
  2047.     } else {
  2048.         menu -e -l "Object" objectMenu;
  2049.     }
  2050.  
  2051.     setUITemplate -popTemplate;
  2052.     
  2053.     formLayout -e -visible ($node == "") $gAENothingSelectedLayout;
  2054.     formLayout -e -visible ($node != "") $gAEBaseLayoutName;
  2055.  
  2056. }
  2057.  
  2058. global proc createAEWindow( string $node, string $listType )
  2059. {
  2060.     global string    $gAttributeEditorWindowName;
  2061.     global int        $gStandardWindowWidthIndex;
  2062.     global string    $gAENothingSelectedLayout;
  2063.     global string    $gAERootLayoutName;
  2064.     global string    $gAEBaseLayoutName;
  2065.     global string    $gAEHeaderLayoutName;
  2066.     global string    $gAETabLayoutName;
  2067.     global string    $gAEControlLayoutName;
  2068.     global int        $gAutoUpdateAttrEdFlag;
  2069.     global string    $gLastViewedAEType;
  2070.     global string    $gRelatedNodes[];
  2071.     global string    $gAETabMarker[];
  2072.     global int        $gAESelectionScriptJob;
  2073.     global int        $gAEConstructionScriptJob;
  2074.  
  2075.     // reset global variables
  2076.     //
  2077.     resetAEGlobalVariables(); // in resetAE.mel
  2078.  
  2079.     window
  2080.         -retain
  2081.         -interactivePlacement
  2082.         -menuBar false
  2083.         -width $gStandardWindowWidthIndex
  2084.         -height 650
  2085.         -title "Attribute Editor"
  2086.         -iconName "Attr Editor"
  2087.         $gAttributeEditorWindowName;
  2088.  
  2089.     createAEWindowContents( $gAttributeEditorWindowName, $node, $listType );
  2090. }
  2091.  
  2092. global proc showEditor( string $node )
  2093. {
  2094.     global string $gAttributeEditorWindowName;
  2095.     global string $gAttributeEditorForm;
  2096.     global int    $gIgnoreAEUpdate;
  2097.  
  2098.     // firewall
  2099.     //
  2100.     if ($node != "" && !`objExists $node`) {
  2101.         warning ("showEditor: Node \"" + $node + "\" does not exist.");
  2102.         return;
  2103.     }
  2104.  
  2105.     // set up the auto-update variables
  2106.  
  2107.     string $listType = "auto";
  2108.     if ( `optionVar -exists "attrEdListType"` ) {
  2109.         $listType = `optionVar -q "attrEdListType"`;
  2110.     } else {
  2111.         optionVar -sv "attrEdListType" $listType;
  2112.     }
  2113.  
  2114.     //     Check for the AEWindow - if it exists and it's visible,
  2115.     //    then show it.  Visible is either open, or iconified.
  2116.     //
  2117.     if ( `window -exists $gAttributeEditorWindowName` ) {
  2118.         if ( `window -q -visible $gAttributeEditorWindowName` ) {
  2119.             showWindow $gAttributeEditorWindowName;
  2120.         } else {
  2121.  
  2122.             //    Get the pref that tells Maya whether it should show
  2123.             //    the AE in the main window, or in a seperate window
  2124.  
  2125.             if( `optionVar -q aeInMainWindow` ) {
  2126.                 //
  2127.                 //    Need to ignore the second update of the AE that will
  2128.                 //    occur in attributeEditorVisibilityStateChange().
  2129.                 //
  2130.                 //    See bug #138766 and #145364.
  2131.                 //
  2132.                 $gIgnoreAEUpdate = true;
  2133.                 setAttributeEditorVisible(true);
  2134.                 $gIgnoreAEUpdate = false;
  2135.  
  2136.             } else {
  2137.                 showWindow $gAttributeEditorWindowName;
  2138.             }
  2139.         }
  2140.     } else {
  2141.         //    Get the pref that tells Maya whether it should show
  2142.         //    the AE in the main window, or in a seperate window
  2143.  
  2144.         if( `optionVar -q aeInMainWindow` ) {
  2145.             if (!isAttributeEditorVisible()) {
  2146.                 //
  2147.                 //    Need to ignore the second update of the AE that will
  2148.                 //    occur in attributeEditorVisibilityStateChange().
  2149.                 //
  2150.                 //    See bug #138766 and #145364.
  2151.                 //
  2152.                 $gIgnoreAEUpdate = true;
  2153.                 setAttributeEditorVisible(true);
  2154.                 $gIgnoreAEUpdate = false;
  2155.             }
  2156.         } else {
  2157.             if (!isAttributeEditorVisible()) {
  2158.                 //
  2159.                 //    Clean up the Attribute Editor in the main Maya window.
  2160.                 //    If this is not done then the AE procs above will try to
  2161.                 //    add the attribute controls to the main window instead of
  2162.                 //    the separate AE window.  The main reason for this is
  2163.                 //    the AE procs are using hard coded short object names
  2164.                 //    instead of the much safer full path names.
  2165.                 //
  2166.                 if ($gAttributeEditorForm != "")
  2167.                 {
  2168.                     string $formLayout [] = `formLayout -query -childArray
  2169.                         $gAttributeEditorForm`;
  2170.                     int $count = `size $formLayout`;
  2171.                     if( $count > 0 ) {
  2172.                         deleteUI $formLayout[0];
  2173.                     }
  2174.                 }
  2175.                 createAEWindow $node "auto";
  2176.                 showWindow $gAttributeEditorWindowName;
  2177.             }
  2178.         }
  2179.     }
  2180.  
  2181.     // set up the option var that specifies the size of the AE pane
  2182.     // and the Notes section.  The main AE window is a paneLayout with
  2183.     // two panes: top for showing Attributes, and the bottom for
  2184.     // showing Notes.  The ratio here is the top has 85 and the
  2185.     // bottom has (100-85) = 15
  2186.     //
  2187.     if ( !`optionVar -exists "attrEdPaneRatio"` ) {
  2188.         optionVar -intValue "attrEdPaneRatio" 85;
  2189.     }
  2190.  
  2191.     updateAE($node);
  2192. }
  2193.  
  2194.  
  2195. global proc showEditorExact ( string $nodeName )
  2196. //
  2197. // Sometimes showEditor will not go to the exact specified node.
  2198. // This happens when the editor is currently showing a related node
  2199. // and you try to showEditor on a node that is currently shown
  2200. // in the tab layout.  This method calls showEditor first, and
  2201. // then ensures that the correct tab is at the front.
  2202. //
  2203. {
  2204.     global string $gAETabLayoutName;
  2205.     global string $gAECurrentTab;
  2206.  
  2207.     showEditor $nodeName;
  2208.     
  2209.     if ( $nodeName != "" && `objExists $nodeName` ){
  2210.     
  2211.         // get the tail of the node name, in case it is a path.
  2212.         //
  2213.         string $tokens[];
  2214.         tokenize($nodeName,"|",$tokens);
  2215.         $nodeName = $tokens[size($tokens)-1];
  2216.     
  2217.         if ( $gAECurrentTab != $nodeName ){
  2218.         
  2219.             // we need to switch tabs
  2220.             //
  2221.             string $tabs[] = `tabLayout -q -tabLabel $gAETabLayoutName`;
  2222.             int $found = 0;
  2223.             int $i;
  2224.             for ( $i=0; $i<size($tabs) && $found == 0; $i++ ){
  2225.                 if ( $tabs[$i] == $nodeName ){
  2226.                     $found = $i+1;
  2227.                 }
  2228.             }
  2229.             if ( $found > 0 ){
  2230.                 tabLayout -e -selectTabIndex $found $gAETabLayoutName;
  2231.                 AEbuildControls;
  2232.             }
  2233.         }
  2234.     }
  2235. }
  2236.     
  2237.  
  2238. global proc showEditorSetListType( string $listType )
  2239. //
  2240. // This call sets the option var to say what kind of
  2241. // list should be displayed, and displays the first element
  2242. // of this kind of list in the attribute editor.  If the
  2243. // new list is empty, the attribute editor isn't changed.
  2244. //
  2245. {
  2246.     // If toggling to auto update, set the flag.  Otherwise reset it.
  2247.     //
  2248.     global int $gAutoUpdateAttrEdFlag;
  2249.     if ( $listType == "auto" ){
  2250.         if ($gAutoUpdateAttrEdFlag) {
  2251.             $gAutoUpdateAttrEdFlag = false;
  2252.             // enable all of the other menu items
  2253.             menuItem -e -en true AEreloadSelectedMenuItem;
  2254.             menuItem -e -en true AEselectedItemsMenuItem;
  2255.             menuItem -e -en true AEdynamicsSubMenu;
  2256.             menuItem -e -en true AEkinematicsSubMenu;
  2257.             menuItem -e -en true AEdeformersSubMenu;
  2258.             menuItem -e -en true AElightSubMenu;
  2259.             menuItem -e -en true AEshadingSubMenu;
  2260.         } else {
  2261.             $gAutoUpdateAttrEdFlag = true;
  2262.             // disable all of the other menu items
  2263.             menuItem -e -en false AEreloadSelectedMenuItem;
  2264.             menuItem -e -en false AEselectedItemsMenuItem;
  2265.             menuItem -e -en false AEdynamicsSubMenu;
  2266.             menuItem -e -en false AEkinematicsSubMenu;
  2267.             menuItem -e -en false AEdeformersSubMenu;
  2268.             menuItem -e -en false AElightSubMenu;
  2269.             menuItem -e -en false AEshadingSubMenu;
  2270.         }
  2271.     }
  2272.  
  2273.     if ( $listType == "auto" || $listType == "selected" ) {
  2274.         menu -e -l "Selected" 
  2275.             -familyImage "menuIconSelected.xpm"
  2276.             objectMenu;
  2277.     } else {
  2278.         menu -e -l "Object" 
  2279.             -familyImage "menuIconObject.xpm"
  2280.             objectMenu;
  2281.     }
  2282.  
  2283.     optionVar -sv "attrEdListType" $listType;
  2284.  
  2285.     string $itemList[] = showEditorGetList();
  2286.  
  2287.     if ( size($itemList) > 0 && $gAutoUpdateAttrEdFlag ){
  2288.         showEditor($itemList[0]);
  2289.     }
  2290. }
  2291.  
  2292.  
  2293.  
  2294. // This procedure is called every time the selected list
  2295. // changes.  If we are in auto-update mode, the attribute
  2296. // editor is updated.  (Unless, of course, nothing is
  2297. // selected.)
  2298. //
  2299. global proc autoUpdateAttrEd()
  2300. {
  2301.     global int      $gAutoUpdateAttrEdFlag;
  2302.     global string   $gAttributeEditorWindowName;
  2303.     global string   $gAEMenuBarLayoutName;
  2304.     global string   $gAECurrentTab;
  2305.  
  2306.     if ( $gAutoUpdateAttrEdFlag ) {
  2307.  
  2308.         //     Also make sure the window is visible or if the 
  2309.         //    menuBarLayout within the AE is being shown, AND
  2310.         //    it's being managed.  No point in updating if 
  2311.         //    it otherwise
  2312.  
  2313.         if( `window -exists $gAttributeEditorWindowName` &&
  2314.             `window -q -visible $gAttributeEditorWindowName`  ||
  2315.             isAttributeEditorVisible() ) {
  2316.  
  2317.             // Get the list of nodes, and find the last one.
  2318.             //
  2319.             string $nodes[] = `selectedNodes`;
  2320.             int $count = size($nodes);
  2321.             if ($count > 0) updateAE($nodes[$count-1]);
  2322.             else updateAE "";
  2323.         }
  2324.     } else if ( !`objExists $gAECurrentTab` ) {
  2325.         updateAE "";
  2326.     }
  2327. }
  2328.  
  2329. // This procedure is called whenever the paneLayout in
  2330. // the Attr Ed window is changed, ie. when the panes are resized
  2331. // The appropriate optionVar is updated.
  2332. //
  2333. global proc paneSizeAttrEd() 
  2334. {
  2335.     global string    $gAERootPaneLayoutName;
  2336.     int $paneSize[] = `paneLayout -q -paneSize $gAERootPaneLayoutName`;
  2337.  
  2338.     // Top pane size is returned as width, height.  We only really
  2339.     // want the height, because width is constrained by the window.
  2340.     // So save the height of the top pane size in an option var.
  2341.     //
  2342.     if( size($paneSize) > 1 ) {
  2343.            optionVar -intValue "attrEdPaneRatio" $paneSize[1];
  2344.     }
  2345. }
  2346.